/**
 * Created by terry on 21/11/26.
 */
$().ready(function (e) {
    setTimeout(function(){
        startIndexAm()
    },1500)

    headScreenMoveStart();
    //imgSwiperInit();

    var index_img_swiper=ImgSwiper.CreateNew();
    index_img_swiper.container=".img-swiper-container";
    index_img_swiper.is_index_swiper=true;
    index_img_swiper.init();

    moveImgCenter();
    startMoveImgX();
    startMoveImgY();
    changeGridInit();

    //newslistSwiperInit();

    if (is_mobile) {
        mobileHeadSwiper();
    }

    loadNewsList();

});

function startIndexAm(){
    $(".bg_box .bg").addClass("zoom_img_am");
    normalTitleAnimate($(".index_head_text_box"));
}

function loadNewsList(){
    $.getJSON("http://test.yuwa.cn/index.php/api/news/index",{ "lang_type": 1, "page_size": 10 },
    function (res) {

        var  data = res.data.data;
        for (var i=1;i<=res.data.data.length;i++){
            var item;
            var item_data=res.data.data[i-1];
            if (i==1){
                item=$($(".dong_tai .dt_item")[0]);
            }
            else{
                item=$($(".dong_tai .dt_item")[0]).clone();

                $(".dong_tai .swiper-wrapper").append(item);
            }
            item.find(".pic").find("img").attr("src",item_data.pic)
            item.find(".date").text(item_data.create_time);
            item.find(".dt_title").text(item_data.title);
            item.find(".dt_sub_title").text(item_data.sub_title);
            item.find("a").attr("href","news-detail.html?id="+item_data.id)
        }

        newslistSwiperInit();
    })

}

var newslist_swiper;

function newslistSwiperInit() {

    var slidesPerView=2;
    if (!is_mobile) {

        if ($(window).outerWidth()>1200){
            slidesPerView=3;
        }
        if ($(window).outerWidth()>1400){
            slidesPerView=4;
        }
        if ($(window).outerWidth()>1600){
            slidesPerView=5;
        }
        if ($(window).outerWidth()>1800){
            slidesPerView=6;
        }
    }
    else {
        slidesPerView=1
    }
        var slidesPerViewBn=is_mobile?1:"auto";
        var len=$(".newslist-swiper-container .swiper-slide").length;
        newslist_swiper = new Swiper('.newslist-swiper-container', {
            slidesPerView: slidesPerViewBn,
            spaceBetween: 40,
            centeredSlides: true,
            loop: true,
            loopAdditionalSlides: 2,
            loopPreventsSlide: false,
            autoplay: {
                delay: 5000
            },
            navigation: {
                nextEl: '.newslist_swiper .swiper-button-next',
                prevEl: '.newslist_swiper .swiper-button-prev'
            },
            disabledClass: "",
            speed: 1000,
            on: {
                slideChangeTransitionStart: function () {
                    //swiper2.update();
                    //clearMoveSwiper();
                    //swiper2.update();

                },
                slideChangeTransitionEnd: function () {
                    /*setTimeout(function () {
                        img_swiper.update()

                        moveImgSwiper();
                    }, 10)*/
                    //console.log(img_swiper);

                    if (newslist_swiper) {
                        changeSwiperNavActive($('.newslist-swiper-container'), newslist_swiper.realIndex, newslist_swiper);
                    }
                },
                slidePrevTransitionStart: function () {
                    //console.log("slidePrevTransitionStart");

                }
            }
        });
        newslist_swiper.params.progress = 0;
        swiperNavInit($('.newslist-swiper-container'), len, newslist_swiper);

}